package com.ruoyi.web.controller.clothing;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.clothing.domain.SysFabric;
import com.ruoyi.clothing.service.ISysFabricService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * fabricController
 *
 * @author weh
 * @date 2024-01-04
 */
@RestController
@RequestMapping("/clothing/fabric")
public class SysFabricController extends BaseController
{
    @Autowired
    private ISysFabricService sysFabricService;

    /**
     * 查询fabric列表
     */
    @PreAuthorize("@ss.hasPermi('clothing:fabric:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFabric sysFabric)
    {
        startPage();
        List<SysFabric> list = sysFabricService.selectSysFabricList(sysFabric);
        return getDataTable(list);
    }

    /**
     * 导出fabric列表
     */
    @PreAuthorize("@ss.hasPermi('clothing:fabric:export')")
    @Log(title = "fabric", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFabric sysFabric)
    {
        List<SysFabric> list = sysFabricService.selectSysFabricList(sysFabric);
        ExcelUtil<SysFabric> util = new ExcelUtil<SysFabric>(SysFabric.class);
        util.exportExcel(response, list, "fabric数据");
    }

    /**
     * 获取fabric详细信息
     */
    @PreAuthorize("@ss.hasPermi('clothing:fabric:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysFabricService.selectSysFabricById(id));
    }

    /**
     * 新增fabric
     */
    @PreAuthorize("@ss.hasPermi('clothing:fabric:add')")
    @Log(title = "fabric", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFabric sysFabric)
    {
        return toAjax(sysFabricService.insertSysFabric(sysFabric));
    }

    /**
     * 修改fabric
     */
    @PreAuthorize("@ss.hasPermi('clothing:fabric:edit')")
    @Log(title = "fabric", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFabric sysFabric)
    {
        return toAjax(sysFabricService.updateSysFabric(sysFabric));
    }

    /**
     * 删除fabric
     */
    @PreAuthorize("@ss.hasPermi('clothing:fabric:remove')")
    @Log(title = "fabric", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysFabricService.deleteSysFabricByIds(ids));
    }
}
